<?php

/**
 * SiteController is the default controller to handle user requests.
 */
class QuestionnaireController extends Controller
{
	/**
	 * Declares class-based actions.
	 */

public function actions(){
	}
	/**
	 * This is the action to handle external exceptions.
	 */
	public function actionError()
	{
	    if($error=Yii::app()->errorHandler->error)
	    {
	    	if(Yii::app()->request->isAjaxRequest)
	    		echo $error['message'];
	    	else
	        	$this->render('error', $error);
	    }
	}
	public function actionIndex()
	{
                    //print_r( Yii::app()->authManager->getAuthAssignments('1'));
                    
        //echo (Yii::app()->user->isAdmin)? 'isAdmin':'no';
       //echo (Yii::app()->user->isGuest)? 'isGuest':'noBody';
        
            $model=Questionnaire::model()->with('testCount')->with('questionCount')->findAll();
            $this->render('index',array(
                'model'=>$model,
            ));
	}
	public function actionView($id)
	{
        $criteria = new CDbCriteria;
        $criteria->condition = 'questionnaire='.$id;
        $model=QuestionnaireTyp::model()->with('questionnaire')->findAll($criteria);
        $this->render('view',array(
                'model'=>$model,
            ));
	}
        
	public function actionCreate()
	{   
            $model=Yii::app()->db->createCommand('SELECT count(*) as cnt from tbl_question')->queryRow();
            $this->render('create', array('model'=>$model));
	}

}
